//
//
//  超长加工界面
//
//


import QtQuick
import QtQuick.Controls.Windows
// import

Item {
    id: extraLongProcessWindowRoot
    width: rootWidth
    height: rootHeight /*- 150*/

    A_NumberKeyboard{
        id: extraLongProcessKeyboard
        isDirectOverwrite: false
    }

    Component.onCompleted: {
        Cpp_PLC.QML_CurrentPage = 2;
        Cpp_PLC.write_Modbus_RTU_Hold_16(48,"4")
    }


    Text{
        anchors.horizontalCenter: extraLongProcessWindowRoot.horizontalCenter
        anchors.top: extraLongProcessWindowRoot.top
        anchors.topMargin: 10
        font.pixelSize: 40
        font.bold: true
        text: qsTr("超长加工界面")
    }

    // 机头角度选择
    MechineAngle{
        id: mechineAngleArea
        anchors.top: extraLongProcessWindowRoot.top
        anchors.horizontalCenter: extraLongProcessWindowRoot.horizontalCenter
    }

    Item{
        id: workAreaBack
        anchors.top: mechineAngleArea.bottom
        anchors.topMargin: -3
        anchors.horizontalCenter: extraLongProcessWindowRoot.horizontalCenter
        width: extraLongProcessWindowRoot.width
        height: 980

        Rectangle{
            anchors.fill: parent
            color: "transparent"
            // color: "red"
            border.width: 3
            border.color: "#F0F8FF"
        }

        A_Label{
            anchors.bottom: heightSetting_Input.top
            anchors.bottomMargin: 10
            anchors.horizontalCenter: workAreaBack.horizontalCenter
            label_Data: qsTr("料  高")
            labelWidth: 300
            labelBack: "transparent"
            labelBorderColor: "transparent"
            visible: !Cpp_PLC.MechineChangeAngleMode
        }

        // A_TextInput{
        //     id: heightSetting_Input
        //     anchors.top: workAreaBack.top
        //     anchors.topMargin: 120
        //     anchors.horizontalCenter: workAreaBack.horizontalCenter
        //     inputWidth: 300
        //     showData: Cpp_PLC.MaterialHeightValue
        //     visible: !Cpp_PLC.MechineChangeAngleMode

        //     onInputFinished: {
        //         // console.log("料高设定: " + inputData)
        //         Cpp_PLC.write_Modbus_RTU_Hold_32(214,inputData)
        //     }

        // }

        A_NumberInput{
            id: heightSetting_Input
            anchors.top: workAreaBack.top
            anchors.topMargin: 120
            anchors.horizontalCenter: workAreaBack.horizontalCenter
            inputWidth: 300
            text: Cpp_PLC.MaterialHeightValue
            visible: !Cpp_PLC.MechineChangeAngleMode

            keyboard: extraLongProcessKeyboard
            onEditingFinished: function(value){
                Cpp_PLC.write_Modbus_RTU_Hold_32(214,value)
            }

        }

        A_Label{
            anchors.bottom: lengthSetting_Input.top
            anchors.bottomMargin: 10
            anchors.horizontalCenter: workAreaBack.horizontalCenter
            label_Data: qsTr("超 长 料 长")
            labelWidth: 300
            labelBack: "transparent"
            labelBorderColor: "transparent"
        }

        A_Label{
            anchors.right: lengthSetting_Input.left
            anchors.rightMargin: 130
            anchors.verticalCenter: lengthSetting_Input.verticalCenter
            // label_Data: "料  长"
            labelBorderColor: "transparent"
            labelBack: "transparent"
            label_Data: Cpp_PLC.ExtraLong_MaterialLengthMin
        }

        Text{
            anchors.verticalCenter: lengthSetting_Input.verticalCenter
            anchors.right: lengthSetting_Input.left
            anchors.rightMargin: 50
            font.pointSize: 40
            text: "<"
        }

        // A_TextInput{
        //     id: lengthSetting_Input
        //     anchors.top: workAreaBack.top
        //     anchors.topMargin: 300
        //     anchors.horizontalCenter: workAreaBack.horizontalCenter
        //     inputWidth: 300
        //     showData: Cpp_PLC.ExtraLong_MaterialLengthValue

        //     onInputFinished: {
        //         // console.log("超长料长: " + inputData)
        //         // Cpp_PLC.write_Modbus_RTU_Hold_32(226,inputData)
        //         if(Number(inputData) < Number(Cpp_PLC.ExtraLong_MaterialLengthMin))
        //         {
        //             Cpp_PLC.write_Modbus_RTU_Hold_32(226,Cpp_PLC.ExtraLong_MaterialLengthMin)
        //         }
        //         else if(Number(inputData) > Number(Cpp_PLC.ExtraLong_MaterialLengthMax))
        //         {
        //             Cpp_PLC.write_Modbus_RTU_Hold_32(226,Cpp_PLC.ExtraLong_MaterialLengthMax)
        //         }
        //         else {
        //             Cpp_PLC.write_Modbus_RTU_Hold_32(226,inputData)
        //         }


        //     }

        // }


        A_NumberInput{
            id: lengthSetting_Input
            anchors.top: workAreaBack.top
            anchors.topMargin: 300
            anchors.horizontalCenter: workAreaBack.horizontalCenter
            inputWidth: 300
            text: Cpp_PLC.ExtraLong_MaterialLengthValue
            // visible: !Cpp_PLC.MechineChangeAngleMode
            minValue: Cpp_PLC.ExtraLong_MaterialLengthMin
            maxValue: Cpp_PLC.ExtraLong_MaterialLengthMax

            keyboard: extraLongProcessKeyboard
            onEditingFinished: function(value){
                Cpp_PLC.write_Modbus_RTU_Hold_32(226,value)
            }

        }


        Text{
            anchors.verticalCenter: lengthSetting_Input.verticalCenter
            anchors.left: lengthSetting_Input.right
            anchors.leftMargin: 50
            font.pointSize: 40
            text: "<"
        }

        A_Label{
            anchors.left: lengthSetting_Input.right
            anchors.leftMargin: 130
            anchors.verticalCenter: lengthSetting_Input.verticalCenter
            // label_Data: "料  长"
            labelBorderColor: "transparent"
            labelBack: "transparent"
            label_Data: Cpp_PLC.ExtraLong_MaterialLengthMax
        }

        A_Label{
            anchors.bottom: extraLongCompensateInput.top
            anchors.bottomMargin: 10
            anchors.horizontalCenter: workAreaBack.horizontalCenter
            label_Data: qsTr("超 长 补 偿")
            labelBorderColor: "transparent"
            labelBack: "transparent"
        }

        // A_TextInput{
        //     id: extraLongCompensateInput
        //     anchors.top: workAreaBack.top
        //     anchors.topMargin: 480
        //     anchors.horizontalCenter: workAreaBack.horizontalCenter
        //     inputWidth: 300
        //     showData: Cpp_PLC.ExtraLong_CompensateValue
        //     onInputFinished: {
        //         // console.log("超长补偿: " + inputData)
        //         Cpp_PLC.write_Modbus_RTU_Hold_32(1382,inputData)
        //     }
        // }

        A_NumberInput{
            id: extraLongCompensateInput
            anchors.top: workAreaBack.top
            anchors.topMargin: 480
            anchors.horizontalCenter: workAreaBack.horizontalCenter
            inputWidth: 300
            text: Cpp_PLC.ExtraLong_CompensateValue

            keyboard: extraLongProcessKeyboard
            onEditingFinished: function(value){
                Cpp_PLC.write_Modbus_RTU_Hold_32(1382,value)
            }

        }


        A_Label{
            anchors.top: workAreaBack.top
            anchors.topMargin: 600
            anchors.horizontalCenter: workAreaBack.horizontalCenter
            label_Data: qsTr("段  数")
            labelBorderColor: "transparent"
            labelBack: "transparent"
        }

        A_Label{
            anchors.top: workAreaBack.top
            anchors.topMargin: 670
            anchors.horizontalCenter: workAreaBack.horizontalCenter
            // label_Data: "段  数"
            labelWidth: 300
            labelBorderColor: "#F0F8FF"
            labelBack: "black"
            label_FontColor: "aqua"
            label_Data: Cpp_PLC.CurrentSegments
        }

        A_Button{
            anchors.top: workAreaBack.top
            anchors.topMargin: 670
            anchors.right: workAreaBack.right
            anchors.rightMargin: 120
            contentText_Data: qsTr("段数清空")
            // contentText_Fontsize: Cpp_Config.Language_Type === 0 ? 40 :  Cpp_Config.Language_Type === 1 ? 20 : 20

            onButtonPressed: {
                console.log("清空段数按下")
                Cpp_PLC.write_Modbus_RTU_Coils(75,"1")
            }

            onButtonReleased: {
                console.log("清空段数松开")
                Cpp_PLC.write_Modbus_RTU_Coils(75,"0")
            }

        }



        // Item{
        //     anchors.top: workAreaBack.top
        //     anchors.topMargin: 800
        //     anchors.horizontalCenter: workAreaBack.horizontalCenter
        //     width: workAreaBack.width
        //     height: 170
        //     visible:false

        //     A_Label{
        //         anchors.top: parent.top
        //         // anchors.topMargin:
        //         anchors.horizontalCenter: parent.horizontalCenter
        //         labelWidth: 300
        //         label_Data: "料高测量值"
        //         labelBorderColor: "transparent"
        //         labelBack: "transparent"
        //     }

        //     A_Label{
        //         anchors.top: parent.top
        //         anchors.topMargin: 70
        //         anchors.horizontalCenter: parent.horizontalCenter
        //         labelBorderColor: "#F0F8FF"
        //         labelWidth: 300
        //         labelBack: "black"
        //         label_FontColor: "aqua"
        //         label_Data: Cpp_PLC.MaterialHeightObservedValue
        //     }

        //     A_Button{
        //         anchors.top: parent.top
        //         anchors.topMargin: 70
        //         anchors.left: parent.left
        //         anchors.leftMargin: 120

        //         contentText_Data: "误差修正"
        //         contentText_Fontsize: 40

        //         onButtonPressed: {
        //             console.log("误差修正按下")
        //             Cpp_PLC.write_Modbus_RTU_Coils(110,"1")
        //         }

        //         onButtonReleased: {
        //             // console.log("误差修正松开")
        //         }
        //     }

        //     Rectangle{
        //         anchors.top: parent.top
        //         anchors.topMargin: 70
        //         anchors.right: parent.right
        //         anchors.rightMargin: 320
        //         width: 30
        //         height: 70
        //         radius: 10
        //         border.width: 1
        //         border.color: "#F0F8FF"
        //         color: Cpp_PLC.ObservingState ? "green" : "black"

        //     }

        //     A_Button{
        //         anchors.top: parent.top
        //         anchors.topMargin: 70
        //         anchors.right: parent.right
        //         anchors.rightMargin: 120
        //         contentText_Data: "测  高"
        //         contentText_Fontsize: 40

        //         onButtonPressed: {
        //             // console.log("测高按钮按下")
        //             Cpp_PLC.write_Modbus_RTU_Coils(108,"1")
        //         }

        //         onButtonReleased: {
        //             // console.log("测高按钮松开")
        //             Cpp_PLC.write_Modbus_RTU_Coils(108,"0")
        //         }
        //     }
        // }
    }



    Item{
        id: buttonAreaBack
        anchors.top: workAreaBack.bottom
        anchors.horizontalCenter: extraLongProcessWindowRoot.horizontalCenter
        width: extraLongProcessWindowRoot.width
        height: 155

        Rectangle{
            anchors.fill: parent
            color: "transparent"
            border.width: 3
            border.color: "#000000"
        }


        A_Button{
            anchors.left: buttonAreaBack.left
            anchors.leftMargin: 20
            anchors.verticalCenter: buttonAreaBack.verticalCenter
            buttonWidth: 150
            buttonHeight: 90
            contentText_Data: qsTr("复  位")
            // contentText_Fontsize: 40

            onButtonPressed: {
                // console.log("复位按下")
                Cpp_PLC.write_Modbus_RTU_Coils(5,"1")
            }

            onButtonReleased: {
                // console.log("复位松开")
                Cpp_PLC.write_Modbus_RTU_Coils(5,"0")
            }
        }

        A_Button{
            anchors.left: buttonAreaBack.left
            anchors.leftMargin: 200
            anchors.verticalCenter: buttonAreaBack.verticalCenter
            buttonWidth: 150
            buttonHeight: 90
            contentText_Data: qsTr("定  位")
            // contentText_Fontsize: 40

            onButtonPressed: {
                // console.log("定位按下")
                Cpp_PLC.write_Modbus_RTU_Coils(102,"1")
            }

            onButtonReleased: {
                // console.log("定位松开")
                Cpp_PLC.write_Modbus_RTU_Coils(102,"0")
            }
        }

        A_Button{
            anchors.left: buttonAreaBack.left
            anchors.leftMargin: 380
            anchors.verticalCenter: buttonAreaBack.verticalCenter
            buttonWidth: 150
            buttonHeight: 90
            contentText_Data: Cpp_PLC.SawsStartState ? qsTr("锯  启") : qsTr("锯  停")
            // contentText_Fontsize:  Cpp_Config.Language_Type === 1 ? 35 :  Cpp_Config.Language_Type === 1 ? 20 : 20
            contentRectangle_BorderWidth: Cpp_PLC.SawsStartState ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.SawsStartState ? "gold" : "black"

            onButtonPressed: {
                // console.log("锯片按下")
                Cpp_PLC.write_Modbus_RTU_Coils(237,"1")
            }

            onButtonReleased: {
                // console.log("锯片松开")
                Cpp_PLC.write_Modbus_RTU_Coils(237,"0")
            }
        }

    }






}
